from flask import Flask, jsonify,request,json
from flask_sockets import Sockets
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
from flask_cors import CORS
import logging

from ums.umsview import ums
from ems.emsview import ems
from pms.pmsview import pms
from dms.dmsview import dms
from ams.amsview import ams
from faceRecogn.faceRecognView import faceRecogn, sockets



# 配置日志文件
logging.basicConfig(filename='applog_socket.txt',filemode='a',level=logging.INFO,
                    format='%(asctime)s - %(module)s - %(levelname)s: %(message)s')
logger = logging.getLogger('app')

logger.info('Test message.')

app = Flask(__name__)
sockets.init_app(app)

CORS(app, resources={r'/*': {'origins': '*'}})

# 用户登录管理    
app.register_blueprint(ums)

# 员工管理    
app.register_blueprint(ems)

# 项目管理    
app.register_blueprint(pms)

# 设备管理    
app.register_blueprint(dms)

# 考勤管理    
app.register_blueprint(ams)

# 注册 WebSocket 蓝图
app.register_blueprint(faceRecogn)  # 将 WebSocket 蓝图的 URL 前缀设置为 /ws


if __name__ == '__main__':
    # 默认接受所有的跨域请求
    app.config['CORS_HEADERS'] = 'Content-Type'
    server = pywsgi.WSGIServer(('101.6.53.143', 5053), app, handler_class=WebSocketHandler)
    print("server start")
    server.serve_forever()
